import {
  ValidatorConstraint,
  ValidatorConstraintInterface,
} from 'class-validator';

@ValidatorConstraint({ name: 'isValidAvatarPath', async: false })
export class IsValidAvatarPath implements ValidatorConstraintInterface {
  validate(text: string) {
    // 使用正则表达式验证格式
    const regex = /^\/avatar\/\d{4}-\d{2}-\d{2}\/.+\.(png|jpg|jpeg|gif)$/;
    return regex.test(text);
  }

  defaultMessage() {
    return 'url格式不正确';
  }
}
